package com.tanhua.db.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanhua.api.SettingsApi;
import com.tanhua.db.mapper.SettingsMapper;
import com.tanhua.model.pojo.Settings;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class SettingsApiImpl implements SettingsApi {

    @Autowired
    private SettingsMapper settingsMapper;

    /**
     * 调用数据层，查询用户的通用设置信息
     * @param userId
     * @return
     */
    @Override
    public Settings findByUserId(Long userId) {
        LambdaQueryWrapper<Settings> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Settings::getUserId,userId);
        Settings settings = settingsMapper.selectOne(queryWrapper);
        return settings;
    }

    /**
     * 调用数据层，新增用户的通用设置信息
     * @param settings
     */
    @Override
    public void saveSettings(Settings settings) {
        settingsMapper.insert(settings);
    }

    /**
     * 调用数据层，修改用户的通用设置信息
     * @param settings
     */
    @Override
    public void updateSettings(Settings settings) {
        settingsMapper.updateById(settings);
    }
}
